<?php
namespace Admin\Controller;
use Think\Controller;
use Common\Common\ConstantUtil;
use Think\Page;
class FlowController extends CommonController {

    public function index() {
        import("ORG.Think.Page");
        $obj =  M("gx_flow")->order("id desc");
        $obj_list = clone $obj;
        $count  = $obj->count();
        $page   = new Page($count,ConstantUtil::ADMIN_PAGE);
        $show   = $page->show();
        $list   = $obj_list->limit($page->firstRow.",".$page->listRows)->select();
        $this->assign([
            "list"  =>  $list ,
            "class" => "Flow" ,
            "page" => $show ,
        ]);
        $this->display("flow/index");


    }

    public function addView() {
        $this->assign([
            "class" => "Flow" ,
        ]);
        $this->display("flow/add");
    }

    public function add(){
        $data = I("post.");
        $result = M("gx_flow")->add($data);
        if(empty($result)) {
            $this->error("添加失败!");
        } else {
            $this->success("添加成功!");
        }
    }

    public function info() {
        $id = I("get.id");
        if(empty($id)) $this->error("参数错误!");
        $list = M("gx_flow")->where(["id"=>$id])->find();
        $this->assign([
            "list"  =>  $list ,
             "class" => "Flow" ,
        ]);
        $this->display("flow/info");
    }

    public function editorView(){
        $id = I("get.id");
        if(empty($id)) $this->error("参数错误!");
        $list = M("gx_flow")->where(["id"=>$id])->find();
        $this->assign([
            "list"=>$list ,
            "class" => "Flow" ,
        ]);
        $this->display("flow/editor");
    }

    public function editor(){
        $data = I("post.");
        $id = $data["id"];
        unset($data["id"]);
        $result = M("gx_flow")->where(["id"=>$id])->save($data);
        if(empty($result)) {
            $this->error("保存失败!");
        } else {
            $this->success("保存成功!");
        }
    }
    public function delete(){

        $id = I("get.id");
        if(empty($id)) $this->error("参数错误!");
        $result = M("gx_flow")->where(["id"=>$id])->delete();
        if(empty($result)) {
            $this->error("删除失败!");
        } else {
            $this->success("删除成功!");
        }
    }
}
